﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using chessLogic;

namespace chessTest
{
    [TestFixture]
    class testPGNImportParser
    {
        private string pgnString = "\r\n[Event \"It\"]\r\n" +
                                "[Site \"Pistyan (Czech Republic)\"]\r\n" +
                                "[Date \"1912.??.??\"]\r\n" +
                                "[Round \"?\"]\r\n" +
                                "[White \"Lowtzky M\"]\r\n" +
                                "[Black \"Duras Oldrich\"]\r\n" +
                                "[Result \"1-0\"]\r\n" +
                                "[ECO \"A56/07\"]\r\n" +
                                "\r\n\r\n" +
                               "1.d4 Nf6 2.c4 c5 3.d5 g6 4.Nc3 d6 \r\n" +
                               "5.e4 Bg7 6.Bd3 Ng4 7.Nge2 Ne5 8.O-O O-O \r\n" +
                               "9.f4 Nxd3 10.Qxd3 f5 11.Ng3 e6 12.Be3 e5 \r\n" +
                               "13.Rae1 exf4 14.Rxf4 g5 15.Rxf5 Bxf5 16.Nxf5 Nd7 \r\n" +
                               "17.Qd2 Ne5 18.Bxg5 Qd7 19.Nb5 Nxc4 20.Qe2 Qxb5 \r\n" +
                               "21.b3 Na3 22.Qg4 Rxf5 23.exf5 Qb4 24.Re4 h5 \r\n" +
                               "25.Qe2 Bd4+ 26.Be3 Qb5 27.Qxh5  1-0\r\n";
       [Test]
       public void testTrueParsePGNStringToParts()
       { 
           PGNImportParser parser = new PGNImportParser("filePath");
           string[] parts = parser.GetPartsPGNString(pgnString);
           Assert.AreEqual(2, parts.Length);
       }
       [Test]
       public void testParseParts()
       {
           PGNImportParser parser = new PGNImportParser("filePath");
           string[] parts = parser.GetPartsPGNString(pgnString);
           Dictionary<string, string> tags = parser.GetTags(parts[0]);
           Assert.AreEqual("It", tags["Event"]);
           Assert.AreEqual("Duras Oldrich", tags["Black"]);
           List<string> moves = parser.GetMoves(parts[1]);
           Assert.AreEqual("d4", moves[0]);
           Assert.AreEqual(53, moves.Count);
       }
       [Test]
       public void testReadFile()
       {
           PGNImportParser parser = new PGNImportParser(@"..\..\testFile.PGN");
           Assert.True(parser.ReadFile().Length > 0);
       }
       [Test]
       public void testTrueCountGame()
       {
            PGNImportParser parser = new PGNImportParser(@"..\..\testFile.PGN");
            parser.Parse();
            Assert.AreEqual(parser.Games.Count, 2);
       }
    }
}
